package org.pragma;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import org.pragma.objects.PragmaObject;

public class PragmaClass extends PragmaObject{
	
	String name;
	Map<String,PragmaBlock> methods = new HashMap<String,PragmaBlock>();
	PragmaBlock constructorMethod;
	
		
	

	public PragmaClass(String string) {
		name = string;
		Method[] ms = this.getClass().getDeclaredMethods();
	}
	
	public PragmaClass() {
	}

	public PragmaClass add(PragmaBlock pragmaMethod) {
		methods.put(pragmaMethod.getName(),pragmaMethod);
		return this;
	}

	public PragmaBlock getMethod(String methodName) {
		if(methodName.equals("new")){
			return constructorMethod;
		}else{
			return methods.get(methodName);
		}
	}
	
	@Override
	public String toString() {
		return name;
	}

	public String getName() {
		return name;
	}

	public PragmaClass setConstructorMethod(PragmaBlock pragmaMethod) {
		constructorMethod = pragmaMethod;
		return this;
	}
	
	public PragmaBlock getConstructorMethod() {
		return constructorMethod;
	}

	@Override
	public String display(String margin) {
		String result =  margin+"Class "+name+"\n";
		if(constructorMethod!=null){
			//result+= margin+displayIndent+"Constructor\n";
			result+= constructorMethod.display(margin+displayIndent);
		}
		for(PragmaBlock method : methods.values()){
			result+= method.display(margin+displayIndent);
		}
		return result;
	}
	
	

}
